//用户表的操作

const UUID = require('uuid');
const { User } = require('../models');


module.exports = {
	//根据昵称查找用户
	findByName: function(nickname){
		return User.findAll({
			where: {
				nickname: {
					$like: '%'+nickname+'%'
				}
			},
			limit: 5
		});
	},
	
	//根据手机号查找该用户
	findByTelephoto: function(telephoto){
		return User.findOne({
			where: {
				telephoto: telephoto
			}
		});
	},
	
	//根据多个条件联合查找
	findByfilter: function(filter_obj){
		return User.findOne({
			where: filter_obj
		});
	},
	
	//创建用户
	createUser: function(obj){
		var uuid = UUID.v1().replace(/-/g,'');
		obj = {uuid, ...obj};
		return User.create(obj);
	},
	
	
	/** 修改资料
	 * @param 用户ID ID
	 * @param {Object} obj
	 */
	updateInfo: function(ID, obj){
		return User.update(obj, {
			where: {
				ID: ID
			}
		});
	}
	
	
}
